package FileIO.stream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;

public class useFileOutputStream {
    public static void main(String[] args) throws IOException {
        OutputStream output = new FileOutputStream("src/main/data/hello.txt");
        try {
            String data = "hello, 123, 老马";
            // OutputStream只能以byte或者bytes数组写文件
            byte[] bytes = data.getBytes(Charset.forName("utf-8"));
            output.write(bytes);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            output.close();
        }
    }
}
